package scsc.web.xzgl.building.apartment.actions;

import java.io.IOException;

import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import scsc.pm.ExpensesPricePm;
import scsc.pub.data.UserContext;
import scsc.pub.db.DBManage;
import scsc.pub.db.PageListData;
import scsc.pub.exception.UnifyUserException;
import scsc.pub.tools.StringUtil;
import scsc.web.system.AppAction;
import scsc.web.system.Constants;
import scsc.web.xzgl.building.apartment.data.ExpensesPriceData;
import scsc.web.xzgl.building.apartment.forms.ExpensesPriceForm;

public class PriceAction extends AppAction {
		
	public PriceAction() throws NamingException {
		super();
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException, UnifyUserException {

		ExpensesPriceForm actionForm = (ExpensesPriceForm) form;
		ExpensesPricePm pm = new ExpensesPricePm();
		String fwd = null;
		ActionErrors errors = new ActionErrors();
		HttpSession session = request.getSession();
		UserContext userContext = (UserContext) session
				.getAttribute("userContext");
		DBManage dbmanage = null;
		if (!errors.isEmpty()) {
			saveErrors(request, errors);
		}
		if (fwd != null) {
			return mapping.findForward(fwd);
		}

	String operAtt = actionForm.getOperAtt();

		if (operAtt == null || StringUtil.trim(operAtt).equals("")) {
			operAtt = Constants.DB_Select;
			actionForm.setOperAtt(operAtt);			
		}
		
		if (operAtt.equals(Constants.DB_Select)) {
			ExpensesPriceData data = actionForm.getConditionData();
			dbmanage = new DBManage();			
			PageListData footer = actionForm.getFooter();
			pm.selectExpensesPrice(userContext,dbmanage,data,footer);
			dbmanage.close();
			fwd = Constants.Price_Perform_ShowDetail_Select_Forward;
		}
		if (!errors.isEmpty()) {
			saveErrors(request, errors);
		}
		return mapping.findForward(fwd);
	}
}
